<!DOCTYPE html>
<html lang="zh_CN">
<head>
<#--引入外部文件-->
    <#include "../common/header.ftl">
</head>
<body>

<div class="container" style="margin-top: 20px;width: 1400px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-2">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-10">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">达人问答问题管理</h1>
                </div>
            </div>
        <#--高级查询--->
            <form class="form-inline" id="searchForm" action="/question/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入标题">
                </div>
                <button id="btn_query" class="btn btn-default">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>编号</th>
                    <th>提问用户</th>
                    <th>标题</th>
                    <th>提问地区</th>
                    <th>提问时间</th>
                    <th>评论总数</th>
                    <th>回答总数</th>
                    <th>浏览量</th>
                    <th></th>
                </tr>
            <#--使用Freemark的指令完成循环迭代-->
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index + 1}</td>
                        <td>${entity.user.nickName}</td>
                        <td>${entity.title}</td>
                        <td>${entity.place}</td>
                        <td>${entity.createTime?string("yyyy-MM-dd")}</td>
                        <td>${entity.commentCount}</td>
                        <td>${entity.answerCount}</td>
                        <td>${(entity.viewCount)!}</td>
                        <td>
                            <a href="javascript:" class="btn btn-warning btn-xs showBtn" data-json='${entity.json}'>
                                <span class="glyphicon glyphicon-hand-right"></span> 显示正文
                            </a>
                            <a href="javascript:" class="btn btn-danger btn-xs delBtn" data-json='${entity.json}'>
                                <span class="glyphicon glyphicon-trash"></span> 删除
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>

            <#include "../common/page.ftl">
        </div>
    </div>
</div>

<#--模态框必须是body的子元素-->
<div class="modal fade" id="contentModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
        <#--模态框标题-->
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">问题正文</h4>
            </div>
        <#--模态框正文-->
            <div class="modal-body">
            <#--填充编辑界面-->
            </div>
        <#--模态框底部按钮-->
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        // 显示提问正文
        $(".showBtn").click(function () {
            //清空模态框的数据
            $(".modal-body").html("");
            //获取当前按钮中的自定义JSON对象
            var obj = $(this).data("json");
            //只有编辑按钮才做数据回显
            if (obj) {
                $(".modal-body").html(obj.content);
            }
            $("#contentModal").modal('show');
        });

        // 删除提问
        $(".delBtn").click(function () {
            var obj = $(this).data("json");
            $.ajax({
                url: "/question/delete.do",
                data: {id:obj.id},
                success:
                    function (data) {
                        if (data.success) {
                            alert("删除成功");
                            location.reload();
                        } else {
                            alert(data.msg);
                            location.reload();
                        }
                    }
            })
        });
    });
</script>

</body>
</html>